<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>虚拟叫号系统</title>
    <!-- 引入element-ui样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>
    <div id="app">
        <audio controls autoplay style="display: none">
            <source id="tts_source" type="audio/mpeg" src="http://tts.baidu.com/text2audio/text2audio?lan=zh&ie=UTF-8&spd=8&text=">
        </audio>
        <label>就诊患者姓名</label>
        <h3>{{detail.currPatientName}}</h3>
        <label>等待人数：{{detail.waitPatientCount}}</label><br/><br/>
        <label>所属科室</label>
        <h3>{{detail.administrativeName}}</h3>
        <label>医生姓名</label>
        <h3>{{detail.doctorName}}</h3>
        <el-button type="primary" @click="callPatient">叫号</el-button>
        <el-button type="warning" @click="treatment">就诊</el-button>
        <el-button type="success" @click="diagnoseFinish">诊结</el-button>
        <el-button type="danger" @click="passPatient">过号</el-button>
    </div>
    <script>
        var app=new Vue({
            el:"#app",
            data:{
                detail:{
                    currPatientName:"无",//当前患者姓名
                    currPatientId:0,//当前患者编号
                    currPatientRegisterId:0,//当前患者对应的挂号表编号
                    waitPatientCount:0,//患者等待人数
                    doctorName:"",//医生姓名
                    doctorId:0,//医生编号
                    administrativeName:"",//科室
                },
                waitPatientList:[],
            },
            mounted:function(){
                this.queryMessageInfo();
            },
            created: function () {//这里是定时器
                //setInterval(this.queryMessageInfo, 1000*10);
            },
            methods:{
                queryMessageInfo:function(){
                    var vm=this;
                    axios.get("medical/doctor/messageInfo").then(function (resp) {
                        console.log(resp);
                        if(resp.data.success){
                            if(resp.data.data.currPatient!=null){
                                vm.detail.currPatientId=resp.data.data.currPatient.patientId;
                                vm.detail.currPatientName=resp.data.data.currPatient.patientName;
                                vm.detail.currPatientRegisterId=resp.data.data.currPatient.registerId;
                            }else{
                                vm.detail.currPatientId=0;
                                vm.detail.currPatientName="无";
                                vm.detail.currPatientRegisterId=0;
                            }
                            vm.detail.doctorName=resp.data.data.doctor.doctorName;
                            vm.detail.doctorId=resp.data.data.doctor.doctorId;
                            vm.detail.administrativeName=resp.data.data.administrativeName;
                            vm.waitPatientList=resp.data.data.waitPatientList;
                            vm.detail.waitPatientCount=resp.data.data.waitPatientList.length;
                            console.log(vm.waitPatientList);
                        }else{
                            alert(resp.data.message)
                        }
                    })
                },
                callPatient:function () {
                    if(this.waitPatientList.length!=0){
                        var s = document.querySelector("#tts_source");
                        s.src="http://tts.baidu.com/text2audio/text2audio?lan=zh&ie=UTF-8&spd=8&text=";
                        var params=this.waitPatientList[0];
                        var vm=this;
                        axios.get("medical/doctor/called",{params:params}).then(function (resp) {
                            if(resp.data.success){
                                var content = "请"+vm.waitPatientList[0].patientName+"到"+vm.detail.administrativeName+"就诊";
                                s.src = s.src + content;
                                s.parentNode.load();
                            }else{
                                alert(resp.data.message)
                            }
                        })
                    }else{
                        alert("当前无候诊病人，可以小憩一下")
                    }

                },
                treatment:function () {
                    if(this.waitPatientList.length!=0){
                        var params={"doctorId":this.detail.doctorId,"currPatient":this.waitPatientList[0].patientName,"registerId":this.waitPatientList[0].registerId};
                        var vm=this;
                        axios.get("medical/doctor/treatment",{params:params}).then(function (resp) {
                            if(resp.data.success!=true){
                                alert(resp.data.message);
                            }else{
                                if(resp.data.data.currPatient!=null){
                                    vm.detail.currPatientId=resp.data.data.currPatient.patientId;
                                    vm.detail.currPatientName=resp.data.data.currPatient.patientName;
                                    vm.detail.currPatientRegisterId=resp.data.data.currPatient.registerId;
                                }else{
                                    vm.detail.currPatientId=0;
                                    vm.detail.currPatientName="无";
                                    vm.detail.currPatientRegisterId=0;
                                }
                                vm.detail.doctorName=resp.data.data.doctor.doctorName;
                                vm.detail.doctorId=resp.data.data.doctor.doctorId;
                                vm.detail.administrativeName=resp.data.data.administrativeName;
                                vm.waitPatientList=resp.data.data.waitPatientList;
                                vm.detail.waitPatientCount=resp.data.data.waitPatientList.length;
                                console.log(vm.waitPatientList);
                            }
                        })
                    }else{
                        alert("当前无候诊病人，可以小憩一下");
                    }
                },
                diagnoseFinish:function () {
                    if(this.detail.currPatientRegisterId!=0){
                        var params={"doctorId":this.detail.doctorId,"registerId":this.detail.currPatientRegisterId};
                        var vm=this;
                        axios.get("medical/doctor/diagnoseFinish",{params:params}).then(function (resp) {
                            if(resp.data.success!=true){
                                alert(resp.data.message);
                            }else {
                                if(resp.data.data.currPatient!=null){
                                    vm.detail.currPatientId=resp.data.data.currPatient.patientId;
                                    vm.detail.currPatientName=resp.data.data.currPatient.patientName;
                                    vm.detail.currPatientRegisterId=resp.data.data.currPatient.registerId;
                                }else{
                                    vm.detail.currPatientId=0;
                                    vm.detail.currPatientName="无";
                                    vm.detail.currPatientRegisterId=0;
                                }
                                vm.detail.doctorName=resp.data.data.doctor.doctorName;
                                vm.detail.doctorId=resp.data.data.doctor.doctorId;
                                vm.detail.administrativeName=resp.data.data.administrativeName;
                                vm.waitPatientList=resp.data.data.waitPatientList;
                                vm.detail.waitPatientCount=resp.data.data.waitPatientList.length;
                                console.log(vm.waitPatientList);
                            }
                        })
                    }else{
                        alert("当前无患者，请先叫号！")
                    }
                },
                passPatient:function () {
                    if(this.waitPatientList.length!=0){
                        var params={"doctorId":this.detail.doctorId,"registerId":this.waitPatientList[0].registerId};
                        var vm=this;
                        axios.get("medical/doctor/passPatient",{params:params}).then(function (resp) {
                            if(resp.data.success!=true){
                                alert(resp.data.message)
                            }else {
                                if(resp.data.data.currPatient!=null){
                                    vm.detail.currPatientId=resp.data.data.currPatient.patientId;
                                    vm.detail.currPatientName=resp.data.data.currPatient.patientName;
                                    vm.detail.currPatientRegisterId=resp.data.data.currPatient.registerId;
                                }else{
                                    vm.detail.currPatientId=0;
                                    vm.detail.currPatientName="无";
                                    vm.detail.currPatientRegisterId=0;
                                }
                                vm.detail.doctorName=resp.data.data.doctor.doctorName;
                                vm.detail.doctorId=resp.data.data.doctor.doctorId;
                                vm.detail.administrativeName=resp.data.data.administrativeName;
                                vm.waitPatientList=resp.data.data.waitPatientList;
                                vm.detail.waitPatientCount=resp.data.data.waitPatientList.length;
                                console.log(vm.waitPatientList);
                            }
                        })
                    }else {
                        alert("当前无候诊患者，无法过号！")
                    }
                },
            }
        })
    </script>
</body>
</html>